<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'west'" title="创建系" style="width:300px;">
		<table class="form_table">
			<tr><td>系名称</td><td><input type="text" id="collegeName" class="textInput"></td></tr>
			<tr><td>系编号</td><td><input type="text" id="collegeId" class="textInput" disabled="disabled"></td></tr>
			<tr><td></td><td><input type="button" id="colCreateButton" class="btnSubmit" value="添加"></td></tr>
		</table>
	</div>
	<div data-options="region:'center'">
		<table class="easyui-datagrid" id="createCollegeList" data-options="url:'uni/colleges',fit:true">
			<thead>
				<tr>
				    <th data-options="field:'lqyxsm',align:'center'">系编码</th>
				    <th data-options="field:'lqyxsmc',halign:'center'">系名称</th>
				</tr>
			</thead>
		</table>
	</div>	
</div>

<script>
$(function(){
	loadCollegeId();

	$('#colCreateButton').click(function() {
		if(!$.trim($('#collegeName').val())) {$.messager.alert('提示','系名称不能为空!');return;}
		if(!$.trim($('#collegeId').val())) {$.messager.alert('提示','系代码不能为空!');return;}

		$.ajax({url:'uni/collegeAct',
			data:{action:'add',collegeId:$('#collegeId').val(),collegeName:$('#collegeName').val()},
			success:function(result) {
				if(result.errorInfo != 'none') {$.messager.alter('提示',result.errorInfo);return;}
				$.messager.alert('提示','添加系成功！');
				loadCollegeId();
				$('#createCollegeList').datagrid('reload');
			}
		})
	});

	function loadCollegeId() {
		$.ajax({url:'uni/nextCollegeId',success:function(result){console.log(result);$('#collegeId').val(result.lqyxsm);}});
	}
});
</script>